//
//  ByNetOrderModel.m
//  beibei_ios
//
//  Created by pro on 16/5/18.
//  Copyright © 2016年 hebidu. All rights reserved.
//

#import "ByNetOrderModel.h"
@implementation ByNetOrderAddModel
-(void)setAttributes:(NSDictionary *)jsonDic{
    [super setAttributes:jsonDic];
    _add_id = jsonDic[@"id"];
}
@end


@implementation ByOrderLogisticModel
- (void)setAttributes:(NSDictionary *)jsonDic{
    [super setAttributes:jsonDic];
}
@end



@implementation ByNetOrderModel

/** 判断订单的合法性 */
- (BOOL)isLegal {
    
    NSString * code = self.code;
    NSString * name =  self.name; // @"%e8%ae%a2%e5%8d%95-T1446561087U29P28";
    NSString * desc = self.desc;  //@"%e8%ae%a2%e5%8d%95-T1446561087U29P28";
    NSString * total_price = self.total_price;
    
    NSString * encode = [NSString stringWithFormat:@"%@%@%@%@", code, name, desc, total_price];
    NSString * encodeKey = [ByCoreCrypt pay_crypt:encode];
    
    return [encodeKey isEqualToString:self.key];
}

- (void)setAttributes:(NSDictionary *)jsonDic {
    
    [super setAttributes:jsonDic];

    NSArray *items = jsonDic[@"items"];
    NSMutableArray *tmp = [[NSMutableArray alloc] init];
    for (NSDictionary *dic in items) {
        ByNetOrderItemModel *model = [[ByNetOrderItemModel alloc] initContentWithDic:dic];
        [tmp addObject:model];
    }
    self.items = [tmp copy];
    self.oid = [jsonDic objectForKey:@"id"];
    
    self.code = jsonDic[@"pay_code"];
    self.total_price = jsonDic[@"pay_money"];
    
   
    NSDictionary *dic = (NSDictionary *)jsonDic[@"_address"];
    if (dic.count != 0) {
        _addressModel = [[ByNetOrderAddModel alloc] initContentWithDic:dic];
    }
    
    dic = (NSDictionary *)jsonDic[@"_express"];
    if (dic.count != 0) {
        _logisticModel = [[ByOrderLogisticModel alloc] initContentWithDic:dic];
    }
  
}

@end
